from threading import Thread, Lock
import time

global_value = 8192


def double_value(lock):
    global global_value
    with lock:
        while global_value < 16384:
            global_value = global_value * 2
            print(global_value)
            time.sleep(1)
    print("reached the maximum！\n")


def half_value(lock):
    global global_value
    with lock:
        while global_value > 1:
            global_value = global_value / 2
            print(global_value)
            time.sleep(1)
    print("reached the minimum！\n")


if __name__ == "__main__":
    # create a lock 创建一个锁
    lock = Lock()

    t1 = Thread(target=double_value, args=(lock,))
    t2 = Thread(target=half_value, args=(lock,))

    t2.start()
    t1.start()
